// 获取用户列表
let	mongoose = require('mongoose'),
	memberUsers = mongoose.model('member_users');

module.exports = (req, res, next) => {
    let params = req.query,
        condition = {};

    if(params.userName){
        condition.userName = params.userName;
    }
    if(params.userGroup){
        condition.userGroup = {
            '$in': params.userGroup
        }
    }
    if(params.mobile){
        condition.mobile = params.mobile
    }
    if(params.sex){
        condition.sex = params.sex
    }
    if(params.email){
        condition.email = params.email
    }
    if(params.job){
        condition.job = {
            '$in': [params.job]
        }
    }
    memberUsers.find(condition)
    .skip(params.pageNo * params.pageSize || 0)
    .limit(params.pageSize || 9999)
    .exec((err, data) => {
        if(err){
            res.json({
                result: 0,
                message: err
            })
        }else{
            // 分页
            let page = null;
            if(params.pageNo){
                page = {
                    pageNo: params.pageNo,
                    pageSize: params.pageSize,
                    total: data.length
                }
            }
            res.json({
                result: 1,
                data: {
                    list: data,
                    page: page
                }
            })
        }
    })
};